using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using Sinacor.Infra.Service.Security.Services;
using Sinacor.Servico.Infra.FileTransfer.Service.ServiceContract;
using Sinacor.Servico.Infra.FileTransfer.Service.DataContract;
using Sinacor.Servico.Infra.FileTransfer.Service.DataContract.Response;
using Sinacor.Servico.Infra.FileTransfer.Service.DataContract.Request;
using System.IO;

namespace Sinacor.Servico.Infra.FileTransfer.Service.ServiceImplementation
{
    public class FileRepositoryService : IFileRepositoryService
    {
        public FileInfoResponse DownloadFile(DownloadRequest request)
        {
            BusinessLogic.FileRepository fileRepository = new BusinessLogic.FileRepository();
            return Translator.BusinessEntityToDataContract.FileRepositoryService.ToFileInfoResponse(
                fileRepository.DownloadFile(
                    Translator.DataContractToBusinessEntity.FileRepositoryService.ToFileInfoEntity(request)
                    )
                );
        }

        public void UploadFile(FileInfoRequest request)
        {
            BusinessLogic.FileRepository fileRepository = new BusinessLogic.FileRepository();
            fileRepository.UploadFile(
                Translator.DataContractToBusinessEntity.FileRepositoryService.ToFileInfoEntity(request)
                );
        }

        public void DeleteFile(StorageFileInfoRequest request)
        {
            BusinessLogic.FileRepository fileRepository = new BusinessLogic.FileRepository();
            fileRepository.DeleteFile(
                Translator.DataContractToBusinessEntity.FileRepositoryService.ToFileInfoEntity(request)
                );
        }

        public List<StorageFileInfoResponse> ListFiles(StorageFileInfoRequest request)
        {
            BusinessLogic.FileRepository fileRepository = new BusinessLogic.FileRepository();
            return Translator.BusinessEntityToDataContract.FileRepositoryService.ToStorageFileInfoResponse(
                fileRepository.ListFiles(
                    Translator.DataContractToBusinessEntity.FileRepositoryService.ToFileInfoEntity(request)
                    )
                );           
        }
    }
}
